package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.HaveFun;
import com.ruoyi.system.mapper.HaveFunMapper;
import com.ruoyi.system.service.IHaveFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class HaveFunServiceImpl implements IHaveFunService {

    @Autowired
    private HaveFunMapper haveFunMapper;

    @Override
    public AjaxResult saveHaveFun(HaveFun haveFun) {
        if (!StringUtils.hasText(haveFun.getTitle())) {
            throw new ServiceException("标题不能为空");
        }
        if (haveFun.getId() == null) {
            haveFunMapper.insertHaveFun(haveFun);
        } else {
            haveFunMapper.updateHaveFun(haveFun);
        }
        return AjaxResult.success("操作成功", haveFun);
    }

    @Override
    public HaveFun getHaveFunById(Long id) {
        return haveFunMapper.selectHaveFunById(id);
    }

    @Override
    public List<HaveFun> getHaveFunList(HaveFun haveFun) {
        return haveFunMapper.selectHaveFunList(haveFun);
    }

    @Override
    public int deleteHaveFunByIds(Long[] ids) {
        return haveFunMapper.deleteHaveFunByIds(ids);
    }
}
